package com.yld.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yld.demo.entity.UserInfo;
import com.yld.demo.mapper.UserInfoMapper;
import com.yld.demo.service.UserInfoService;
import com.yld.demo.util.redis.CacheClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;


@Slf4j
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
    @Resource
    private CacheClient cacheClient;

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Override
    public UserInfo selectById(Integer id) throws InterruptedException {
        UserInfo user = cacheClient.queryWithLogicalExpire("user", id, UserInfo.class, this::getById, 2L, TimeUnit.MINUTES);
        return user;
    }

    @Override
    public List<UserInfo> selectAllLimit(int num) {
        return userInfoMapper.listByLimit(num);
    }
}
